package com.luck.easyfoodbatch.custom;

import android.os.Build;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * Created by HanHailong on 15/9/27.
 */
public class ScalePageTransformer implements ViewPager.PageTransformer {

    public static final float MAX_SCALE = 1.2f;
    public static final float MIN_SCALE = 0.6f;
    public static final float MIDDLE_SCALE = 0.8f;

    @Override
    public void transformPage(View page, float position) {

        if (position < -1) {
            position = -1;
        } else if (position > 1) {
            position = 1;
        }

        float tempScale = position < 0 ? 1 + position : 1 - position;

        float slopeX = (MAX_SCALE - MIN_SCALE) / 1;
        float slopeY= (MAX_SCALE - MIDDLE_SCALE) / 1;
        //一个公式
        float scaleValueX = MIN_SCALE + tempScale * slopeX;
        float scaleValueY = MIN_SCALE + tempScale * slopeY;

        page.setScaleX(scaleValueX);
        page.setScaleY(scaleValueY);



        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            page.getParent().requestLayout();
        }
    }
}
